<template>
	<view class="changeList">
		<scroll-view scroll-y="true"  class="scrolly" :scroll-into-view="viewId">
			<view class="box">
				<view class="title">
					<text class="iconfont iconweibiaoti- dingwei"></text> 当前城市
				</view>
				<view class="current-city">
					{{currentCity}}
				</view>
			</view>
			<view class="box">
				<view class="title">
					<text class="iconfont iconweibiaoti- hot"></text> 热门城市
				</view>
				<view class="hotlist">
					<view class="item" v-for="(item,index) in hotCityList" :key="index" @click="changeCity(item.city)">
						{{item.city}}
					</view>
				</view>
			</view>
			<view class="box-list" v-for="(group,index) in city" :key="index" :id="group.initial">
				<view class="initial">
					{{group.initial}}
				</view>
				<view class="city-name" v-for="(city,index2) in group.list" :key="index2" @click="changeCity(city.name)">
					{{city.name}}
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	
	export default {
		props:['city','letter'],
		data() {
			return {
				currentCity:'上海',
				viewId:'C',
				hotCityList:[{
						city:'深圳'
					},{
						city:'上海'
					},{
						city:'北京'
					},{
						city:'广州'
					},{
						city:'杭州'
					},{
						city:'无锡'
					},{
						city:'郑州'
					},{
						city:'南京'
					},{
						city:'厦门'
					}]
				};
		},
		created() {
			uni.getStorage({
				key:'city',
				success:(res)=>{
					this.currentCity = res.data
				},
				error(err){
					this.currentCity = '上海'
				}
			})
		},
		methods:{
			changeCity(name){
				uni.setStorage({
					key:'city',
					data:name
				})
				uni.getStorage({
					key:'city',
					success:(res)=>{
						this.currentCity = res.data
					}
				})
				uni.redirectTo({
					url:'/pages/city/city'
				})
			}
		},
		watch:{
			letter(val){
				this.viewId = val
			}
		}
	}
</script>

<style lang="scss">
	.scrolly{
		height: 100%;
	}
	.changeList{
		width: 100%;
		background-color: #000000;
		height: 100%;
		z-index: 19;
		.box{
			background-color: #222222;
			margin-top: 10px;
			padding: 12px 0;
			.title{
				color: #ffffff;
				font-size: 14px;
				margin-left: 15px;
				.dingwei{
					color: #4CD964;
				}
				.hot{
					color: #DD524D;
				}
			}
			.current-city{
				margin-left: 15px;
				margin-top: 15px;
				color: #aaaaaa;
				font-size: 12px;
			}
			.hotlist{
				width: 100%;
				overflow: hidden;
				margin-top: 10px;
				.item{
					width: 30%;
					float: left;
					margin-top: 5px;
					margin-left: 2.5%;
					height: 28px;
					line-height: 28px;
					text-align: center;
					font-size: 13.5px;
					background-color: #333333;
					color: #ffffff;
				}
			}
		}
		.box-list{
			padding: 8px 5px;
		}
		.initial{
			height: 25px;
			line-height: 25px;
			background-color: #000000;
			padding-left: 10px;
			color: #666666;
			font-size: 12px;
		}
		.city-name{
			background-color: #222222;
			height: 40px;
			line-height: 40px;
			padding-left: 10px;
			color: #aaaaaa;
			font-size: 15px;
			// margin-bottom: 5px;
		}
	}
</style>
